package com.hope.hotel.service.Impl;

import com.hope.hotel.common.Result;
import com.hope.hotel.entity.DAO.LoginDAO;
import com.hope.hotel.entity.po.User;
import com.hope.hotel.mapper.UserMapper;
import com.hope.hotel.service.AdminService;
import com.hope.hotel.utils.TokenUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * @作者 TD
 * @日期 2025/5/26
 */

@Service
@RequiredArgsConstructor
public class AdminServiceImpl implements AdminService {

    private final UserMapper userMapper;

    @Override
    public Result adminLogin(LoginDAO loginDAO) {
        // 验证密码，账号
        User user;
        try {
            user = userMapper.checkAdminLogin(loginDAO);
            // 生成token
            String token = TokenUtil.generateToken(user.getUserId(),"admin");
            return Result.success(token);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("账号或密码错误");
        }

    }


}
